package com.zyg.dao;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.zyg.pojo.EchartsData;
import com.zyg.pojo.Grade;
import com.zyg.pojo.Major;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.io.Serializable;
import java.util.List;

@Mapper
public interface MajorMapper extends BaseMapper<Major> {
    @Override
    @Select("select major_id,major_name,grade_id from major")//一定要特别注意@One注解的使用，使用了@one就不用写连接表的sql语句
    @Results(id="majorMap", value = {
            @Result(property="majorId",column="major_id"),
            @Result(property="majorName",column="major_name"),
            @Result(property="grade",column="grade_id",javaType= Grade.class,
                    one=@One(select="com.zyg.dao.GradeMapper.selectById",fetchType = FetchType.LAZY )),

    })
    List<Major> selectList(IPage<Major> page, @Param(Constants.WRAPPER) Wrapper<Major> queryWrapper);
    @Override
    @Select("select * from major where major_id=#{majorId}")
    @Results(id="majorMap1", value = {
            @Result(property="majorId",column="major_id"),
            @Result(property="majorName",column="major_name"),
            @Result(property="grade",column="grade_id",javaType= Grade.class,
                    one=@One(select="com.zyg.dao.GradeMapper.selectById",fetchType = FetchType.LAZY )),

    })
    Major selectById(Serializable majorId);
    @Select("select g.grade_name as name,count(*) as value from  major m inner join sys_grade g\n" +
            "        on m.grade_id = g.grade_id group by g.grade_id")
    List<EchartsData> getIndexData();
}
